home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / Savant.exe / disk1 / data1.cab / Program_Files / cgi-bin / cgitest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-23  |  2.3 KB  |  62 lines

  1. // This example CGI program shows how to use C and C++ programs with the
  2. // Savant web server to create dynamically generated content.
  3.  
  4. // For more information about Savant, visit
  5. // http://savant.sourceforge.net
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <iostream.h>
  11.  
  12. void main()
  13. {
  14.   char query[128];
  15.  
  16. //Read in query string
  17.   cin >> query;
  18.  
  19. //Output HTTP header info
  20.   cout << "Content-type: text/html\n\n";
  21.  
  22. //Output HTML page
  23.   cout << "<html>" << endl;
  24.   cout << "<head>" << endl;
  25.   cout << "<title>CGI Test</title>" << endl;
  26.   cout << "</head>" << endl;
  27.   cout << "<body>" << endl;
  28.   cout << "<center><b><font face=\"Arial,Helvetica\"><font color=\"#0000FF\"><font size=+4>" << endl;
  29.   cout << "CGI Test Results</font></font></font></b></center>" << endl;
  30.   cout << "<p><br><br>" << endl;
  31.   cout << "<p><font face=\"Arial,Helvetica\">Results from the HTML form:</font>" << endl;
  32.   cout << "<p><font face=\"Arial,Helvetica\">Color:</font>" << endl;
  33.   cout << "<table BORDER CELLSPACING=0 WIDTH=\"50\" HEIGHT=\"25\" >" << endl;
  34.   cout << "<tr><td BGCOLOR=" << endl;
  35.  
  36. //Output the appropriate color code based on what the user selected in the
  37. //HTML form
  38.   if (strstr(query, "red"))
  39.     cout << "\"#FF0000\"";
  40.   if (strstr(query, "green"))
  41.     cout << "\"#00FF00\"";
  42.   if (strstr(query, "blue"))
  43.     cout << "\"#0000FF\"";
  44.  
  45.   cout << "> </td></tr>" << endl;
  46.   cout << "</table><p>" << endl;
  47.  
  48. //Print out some of the more useful CGI environment variables.  You can use
  49. //these in your programs for a variety of reasons.
  50.   cout << "CONTENT_LENGTH (length of query string): " << getenv("CONTENT_LENGTH") << "<br>" << endl;
  51.   cout << "SERVER_SOFTWARE : " << getenv("SERVER_SOFTWARE") << "<br>" << endl;
  52.   cout << "SERVER_NAME : " << getenv("SERVER_NAME") << "<br>" << endl;
  53.   cout << "SERVER_PROTOCOL : " << getenv("SERVER_PROTOCOL") << "<br>" << endl;
  54.   cout << "SERVER_PORT : " << getenv("SERVER_PORT") << "<br>" << endl;
  55.   cout << "REMOTE_HOST : " << getenv("REMOTE_HOST") << "<br>" << endl;
  56.   cout << "REMOTE_ADDR : " << getenv("REMOTE_ADDR") << "<br>" << endl;
  57.   cout << "HTTP_USER_AGENT : " << getenv("HTTP_USER_AGENT") << "<br>" << endl;
  58.   cout << "HTTP_REFERER : " << getenv("HTTP_REFERER") << "<br>" << endl;
  59.   cout << "</body></html>" << endl;
  60.  
  61. }
  62.